package com.rd.student.dashuju.wangbo.exercise0728;

import java.io.*;

public class TestCopy {

    public static void main(String[] args) throws Exception {
        File srcFile = new File("stream.txt");
        File destFile = new File("streamCopy.txt");
        copyFile(srcFile, destFile);
    }

    public static void copyFile(File srcFile, File destFile) throws Exception {

        if (!destFile.exists()) {
            destFile.createNewFile();
        }
        InputStream is = new FileInputStream(srcFile);
        OutputStream os = new FileOutputStream(destFile);
//        byte[] bytesArr = new byte[(int) srcFile.length()];
        byte[] bytesArr = new byte[1024];

        int len = 0;
        while ((len = is.read(bytesArr)) != -1) {
            os.write(bytesArr,0,len);
        }


        is.close();
        os.close();

    }
//        先从源文件中读取数据，再将数据放到目标文件中
//    源文件存在，目标文件不存在


}
